<?php
use app\models\Mall;
use app\widgets\MallMBottomToolbarWidget;
use yii\helpers\Url;

$web = Url::base();
//$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
//$integral_unit = \app\models\Mall::getCurrentInstitutionIntegralUnit();
$institution_code = Mall::getCurrentInstitutionCode();

$this->title = '卡卷列表';

$goodsList = $result['goodsList'];
?>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/virtual-coupon-list.css"/>
<div class="main">
    <?php
    if (count($goodsList) > 0) {
        ?>
        <div class="paging">
            <a href="javascript:void(0);" onclick="prePage()">
                <div class="prev f-l">
                    <p class="color-cur"><span><</span>上一页</p>
                </div>
            </a>
            <div class="pagination f-l">
                <p class="color-cur"><span><?= $result['pageNo'] ?></span>/<span><?= $result['totalPage'] ?></span></p>
            </div>
            <a href="javascript:void(0);" onclick="nextPage()">
                <div class="next f-l">
                    <p class="color-cur">下一页<span>></span></p>
                </div>
            </a>
        </div>
        <div class="goods-list">
            <ul>
                <?php
                foreach ($goodsList as $item) {
                    ?>
                    <li>
                        <a href="<?= Url::to(['mall-m/virtual-coupon-detail', 'shopId' => $item['shopId'], 'institution_code' => $institution_code]) ?>">
                            <img src="<?= $item['info']->picBg ?>"/>
                            <p class="title"><?= $item['info']->title ?></p>
                            <p class="time">领取时间至：<span><?= date('Y-m-d', $item['info']->dateValidTo) ?></span></p>
                            <div class="get">
                                <del class="original-price">¥:<?= $item['info']->price ?></del>
                                <p class="draw">免费领取</p>
                            </div>
                        </a>
                    </li>
                    <?php
                }
                ?>
                <!--<li>
                    <a href="">
                        <img src="img/goods-list-img.jpg"/>
                        <p class="title">100元养车大礼包</p>
                        <p class="time">领取时间至：<span>2016-10-31</span></p>
                        <div class="get">
                            <del class="original-price">¥:100.00</del>
                            <p class="draw">免费领取</p>
                        </div>
                    </a>
                </li>-->


            </ul>
        </div>
        <div class="paging">
            <a href="javascript:void(0);" onclick="prePage()">
                <div class="prev f-l">
                    <p class="color-cur"><span><</span>上一页</p>
                </div>
            </a>
            <div class="pagination f-l">
                <p class="color-cur"><span><?= $result['pageNo'] ?></span>/<span><?= $result['totalPage'] ?></span></p>
            </div>
            <a href="javascript:void(0);" onclick="nextPage()">
                <div class="next f-l">
                    <p class="color-cur">下一页<span>></span></p>
                </div>
            </a>
        </div>
        <?php
    } else {
        ?>
        <style>
            body {
                background: #ffffff;
            }
        </style>
        <div class="page-prompt-5">
            <img class="page-prompt" src="<?= $web ?>/images/mall-m/page-prompt-6.jpg"/>
            <p class="title">抱歉，没有找到符合条件的商品</p>
        </div>
        <?php
    }
    ?>
    <div class="tab-frame-margin-bottom"></div>
    <?=MallMBottomToolbarWidget::widget(['actionName'=>''])?>
</div>
<script>
    $(function ($) {
        //设置翻页按钮显示
        $('.prev p').addClass('color-cur');
        $('.next p').addClass('color-cur');
        if (currentPage <= 1) {
            $('.prev p').removeClass('color-cur');
        }
        if (currentPage >= max_page) {
            $('.next p').removeClass('color-cur');
        }
    });
    function href_page(page) {

        var href = window.location.href;
        if (page > 0) {
            href = setUrlParam(href, 'page', page);
        }
        window.location.href = href;

    }
    var currentPage =<?=$result['pageNo']?>;
    var max_page =<?=$result['totalPage']?>;
    function prePage() {
        if (currentPage != null && currentPage != '' && currentPage > 1) {
            currentPage--;
            href_page(currentPage);
        }
    }

    function nextPage() {
        if (currentPage != null && currentPage != '' && currentPage < max_page) {
            currentPage++;
            href_page(currentPage);
        }
    }
</script>
